package com.tian.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.tian.mapper.NavMapper;
import com.tian.pojo.Nav;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class NavServiceImpl implements NavService{
    @Autowired
    private NavMapper navMapper;
    /**
     *
     * 1.查询一级列表信息 条件parent_id=0
     * @return
     */
    @Override
    public List<Nav> getRightsList() {
        QueryWrapper<Nav> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("parent_id", 0 );
        List<Nav> list = navMapper.selectList(queryWrapper);
        //遍历list集合数据
        for(Nav nav : list){
            queryWrapper.clear();
            //根据一级的ID,查询自己信息
            queryWrapper.eq("parent_id", nav.getId() );
            List<Nav> children = navMapper.selectList(queryWrapper);
            nav.setChildren(children);
        }
        return list;
    }
}
